/*

 * Copyright (C) 2021 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */
package io.karim.materialtabs.sample.slice;

import io.karim.materialtabs.sample.ResourceTable;
import io.karim.materialtabs.sample.widget.ActionBar;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;

public class ActionBarSlice extends AbilitySlice {
    ActionBar actionBar01;
    ActionBar actionBar02;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_action_bar);

        actionBar01 = (ActionBar) findComponentById(ResourceTable.Id_actionbar01);
        actionBar02 = (ActionBar) findComponentById(ResourceTable.Id_actionbar02);
        actionBar01.addClickListener(new ActionBar.ActionBarListener() {
            @Override
            public void click(ActionBar.ActionBarType clickType, int position) {
                if(clickType == ActionBar.ActionBarType.LEFT_ICON){
                    new ToastDialog(getContext())
                            .setAlignment(LayoutAlignment.CENTER)
                            .setText("左边按钮点击")
                            .show();
                }else if(clickType == ActionBar.ActionBarType.RIGHT_ICON){
                    new ToastDialog(getContext())
                            .setAlignment(LayoutAlignment.CENTER)
                            .setText(String.format("右边第%s个钮点击", position))
                            .show();
                }
            }
        });

        actionBar02.addClickListener((clickType, position) -> {
            if(clickType == ActionBar.ActionBarType.LEFT_ICON){
                new ToastDialog(getContext())
                        .setAlignment(LayoutAlignment.CENTER)
                        .setText("左边按钮点击")
                        .show();
            }else if(clickType == ActionBar.ActionBarType.RIGHT_ICON){
                new ToastDialog(getContext())
                        .setAlignment(LayoutAlignment.CENTER)
                        .setText(String.format("右边第%s个钮点击", position))
                        .show();
            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

}
